# 主模块
def main():
    # 接收用户输入的字符串
    user_input = input("请输入字符串：")
    # 判断字符串长度是否合法
    if len(user_input) > 0 and len(user_input) <= 255:
        # 调用letter模块
        letters = letter(user_input)
        # 调用reverse模块
        reversed_letters = reverse(letters)
        # 调用enCode模块
        encoded_str = enCode(reversed_letters)
        # 输出加密后的字符串
        print("加密后的字符串为：", encoded_str)
    else:
        print("输入字符串长度不合法！")

# letter模块
def letter(user_input):
    # 剔除非英文字符
    letters = ''.join(filter(str.isalpha, user_input))
    return letters

# reverse模块
def reverse(letters):
    # 将全英文字符反转
    reversed_letters = ''
    for i in range(len(letters)-1, -1, -1):
        reversed_letters += letters[i]
    return reversed_letters

# enCode模块
def enCode(reversed_letters):
    # 凯撒密码加密
    encoded_str = ''
    for letter in reversed_letters:
        if letter.islower():
            encoded_str += chr((ord(letter) - 97 + 3) % 26 + 97)
        elif letter.isupper():
            encoded_str += chr((ord(letter) - 65 + 3) % 26 + 65)
    return encoded_str

if __name__ == '__main__':
    main()
